package com.ziyuan.controller;

import com.ziyuan.pojo.Result;
import com.ziyuan.utils.AliOssUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

@RestController
public class FileupLoadController {
    @PostMapping("/upload")
    public Result upload(MultipartFile file) throws IOException {
        String originalFilename = file.getOriginalFilename();
        String string = UUID.randomUUID()+originalFilename.substring(originalFilename.lastIndexOf("."));
//        file.transferTo(new File("C:\\Users\\jzy23\\Desktop\\新建文件夹\\"+string));
        String url = AliOssUtil.uploadFile(string, file.getInputStream());
        return Result.success(url);
    }

}
